home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
- Subject: Re: How can I check whether I file exists in a multi-user environment?
- Date: 30 Mar 1996 10:21:01 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jjn1d$clu@solutions.solon.com>
- References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <Dp1oM8.Cns@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
- > * * * * C A U T I O N * * * *
- >Although this will work in many implementations, to the best of my knowledge
- >it is *NOT* ANSI C.
-
- Then why post it to comp.lang.c? Why not just email it to the user, along
- with a pointer to the correct newsgroup? (Which is even in the newsgroups
- list...)
-
- >#include <io.h>
- >int file_exists (char *filename) {
- > return (access(filename, 0) == 0);
- >} /* returns -1 if file exists, 0 if it does not */
-
- The reason this is a poor solution is that it doesn't test for existance,
- it tests for accessibility. In modern environments, such as NT or Unix,
- it is quite possible for a file to exist but be inaccessible. There is
- no real way in such environments to test for existance; you aren't allowed to
- know whether someone else has a file they don't want you to know about.
-
- Also, on any POSIX-like system, access is in <unistd.h>. This may be useful
- to someone planning to work with multiple systems, or in any event NT, which
- has some POSIX to it.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-